package com.bsoft.mvpmy.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.bsoft.mvpmy.R;
import com.bsoft.mvpmy.utils.Node;
import com.bsoft.mvpmy.utils.adapter.TreeListViewAdapter;

import java.util.List;

/**
 * User: ZRJ
 * Date: 2016/11/30
 * Email: 471564517@qq.com
 * Description:
 */
public class SimpleTreeListViewAdapter<T> extends TreeListViewAdapter<T>
{
	//设置当前选中项
	private int  _chooseId = 1;

	public SimpleTreeListViewAdapter(ListView tree, Context context,
									 List<T> datas, int defaultExpandLevel)
			throws IllegalArgumentException, IllegalAccessException
	{
		super(tree, context, datas, defaultExpandLevel);
	}

	@Override
	public View getConvertView(Node node, int position, View convertView,
							   ViewGroup parent)
	{
		ViewHolder holder = null;
		if (convertView == null)
		{
			convertView = mInflater.inflate(R.layout.list_item, parent, false);
			holder = new ViewHolder();
			holder.mIcon = (ImageView) convertView
					.findViewById(R.id.id_item_icon);
			holder.mText = (TextView) convertView
					.findViewById(R.id.id_item_text);
			holder.iv_next = (ImageView) convertView.findViewById(R.id.iv_next);

			convertView.setTag(holder);
		} else
		{
			holder = (ViewHolder) convertView.getTag();
		}

		if (node.getIcon() == -1)
		{
			holder.mIcon.setVisibility(View.INVISIBLE);
		} else
		{
			holder.mIcon.setVisibility(View.VISIBLE);
			holder.mIcon.setImageResource(node.getIcon());



		}

		holder.mText.setText(node.getName());
		if(_chooseId==node.getId()){
			holder.mText.setTextColor(Color.parseColor("#21D87E"));
		}else{
			holder.mText.setTextColor(Color.parseColor("#333333"));
		}

		return convertView;
	}

	public void set_chooseId(int _chooseId) {
		this._chooseId = _chooseId;
		notifyDataSetChanged();
	}

	private class ViewHolder
	{
		ImageView mIcon;
		TextView mText;
		ImageView iv_next;
	}

	/**
	 * 动态插入节点
	 * 
	 * @param position
	 * @param string
	 */
//	public void addExtraNode(int position, String string,String desc)
//	{
//		Node node = mVisibleNodes.get(position);
//		int indexOf = mAllNodes.indexOf(node);
//		// Node
//		Node extraNode = new Node(-1, node.getId(), string,desc);
//		extraNode.setParent(node);
//		node.getChildren().add(extraNode);
//		mAllNodes.add(indexOf + 1, extraNode);
//
//		mVisibleNodes = TreeHelper.filterVisibleNodes(mAllNodes);
//		notifyDataSetChanged();
//
//	}


}
